package com.cqc.listviewchoicedemo.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.LinearLayout;

import com.cqc.listviewchoicedemo.R;

/**
 * Created by ${cqc} on 2017/3/13.
 */

public class ChoiceLinearLayout extends LinearLayout implements Checkable {

    private boolean mChecked;

    public ChoiceLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setChecked(boolean checked) {
        mChecked = checked;
        //改变item的背景色
        setBackgroundResource(checked? R.color.colorPrimary : android.R.color.transparent);
    }

    @Override
    public boolean isChecked() {
        return mChecked;
    }

    @Override
    public void toggle() {
        setChecked(!mChecked);
    }
}
